<h2><a name="ssi" id="ssi">Server Side Includes</a></h2>
<p>Server Side Includes (SSI) present a server administrator with
several potential security risks.</p>
<p>The first risk is the increased load on the server. All
SSI-enabled files have to be parsed by Apache, whether or not
there are any SSI directives included within the files. While this
load increase is minor, in a shared server environment it can become
significant.</p>
<p>SSI files also pose the same risks that are associated with CGI
scripts in general. Using the "exec cmd" element, SSI-enabled files
can execute any CGI script or program under the permissions of the
user and group Apache runs as, as configured in httpd.conf.</p>
<p>There are ways to enhance the security of SSI files while still
taking advantage of the benefits they provide.</p>
<p>To isolate the damage a wayward SSI file can cause, a server
administrator can enable <a href="../suexec.html">suexec</a> as
described in the <a href="#cgi">CGI in General</a> section</p>
<p>Enabling SSI for files with .html or .htm extensions can be
dangerous. This is especially true in a shared, or high traffic,
server environment. SSI-enabled files should have a separate extension,
such as the conventional .shtml. This helps keep server load at a
minimum and allows for easier management of risk.</p>
<p>Another solution is to disable the ability to run scripts and
programs from SSI pages. To do this replace <code>Includes</code>
with <code>IncludesNOEXEC</code> in the <code class="directive"><a href="../mod/core.html#options">Options</a></code> directive. Note that users may
still use <--#include virtual="..." --> to execute CGI scripts if
these scripts are in directories desginated by a <code class="directive"><a href="../mod/mod_alias.html#scriptalias">ScriptAlias</a></code> directive.</p>
<h2><a name="protectserverfiles" id="protectserverfiles">Protect Server Files by Default</a></h2>
<p>One aspect of Apache which is occasionally misunderstood is the
feature of default access. That is, unless you take steps to change it,
if the server can find its way to a file through normal URL mapping
rules, it can serve it to clients.</p>
<p>For instance, consider the following example:</p>
<div class="example"><p><code>
# cd /; ln -s / public_html <br />
Accessing <code>http://localhost/~root/</code>
</code></p></div>
<p>This would allow clients to walk through the entire filesystem. To
work around this, add the following block to your server's
configuration:</p>
<div class="example"><p><code>
<Directory /> <br />
Order Deny,Allow <br />
Deny from all <br />
</Directory>
</code></p></div>
<p>This will forbid default access to filesystem locations. Add
appropriate <code class="directive"><a href="../mod/core.html#directory">Directory</a></code> blocks to
allow access only in those areas you wish. For example,</p>
<div class="example"><p><code>
<Directory /usr/users/*/public_html> <br />
Order Deny,Allow <br />
Allow from all <br />
</Directory> <br />
<Directory /usr/local/httpd> <br />
Order Deny,Allow <br />
Allow from all <br />
</Directory>
</code></p></div>
<p>Pay particular attention to the interactions of <code class="directive"><a href="../mod/core.html#location">Location</a></code> and <code class="directive"><a href="../mod/core.html#directory">Directory</a></code> directives; for instance, even
if <code><Directory /></code> denies access, a <code>
<p>Also be wary of playing games with the <code class="directive"><a href="../mod/mod_userdir.html#userdir">UserDir</a></code> directive; setting it to
something like "./" would have the same effect, for root, as the first
example above. If you are using Apache 1.3 or above, we strongly
recommend that you include the following line in your server
<p>in your <a href="../logs.html#accesslog">Access Log</a>. This means
you probably commented out the following in your server configuration
file:</p>
<div class="example"><p><code>
<Files ~ "^\.ht"> <br />
Order allow,deny <br />
Deny from all <br />
</Files>
</code></p></div>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="../en/misc/security_tips.html" title="English"> en </a> |
<a href="../ko/misc/security_tips.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
</div><div id="footer">
<p class="apache">Copyright 1995-2006 The Apache Software Foundation or its licensors, as applicable.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>